import BaseUtil from '@/BaseUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 波浪形态
 **/
export default class BossSpell_WavePos extends AbilityBase {
    static instance: BossSpell_WavePos;
    constructor(id: string = 'Mst1') {
        super(id);
        BossSpell_WavePos.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('波浪形态', source);
        target = SelectUtil.getRandomEnemyInRange(source, 1000);
        let x = GetUnitX(target);
        let y = GetUnitY(target);
        let mark = AddSpecialEffect(BossAbilityManagerInstance.SpellMark, x, y);
        BaseUtil.runLater(1, () => {
            ShowUnit(source, false);
            MovementCommon.LineMissile({
                angle: MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), x, y),
                distance: 800,
                speed: 800,
                radius: 100,
                missile: 'Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveMissile.mdl',
                caster: source,
                is_through: true,
                onHit: this.onHit.bind(this),
                onFinish: this.onFinish.bind(this),
                other: mark,
            });
            source = null;
            mark = null;
        });
    }
    onHit(p: LineMissileConfig, hit: unit) {
        DamageSystemInstance.applyIceDamage(hit, p.caster, 1500);
    }
    onFinish(p: LineMissileConfig) {
        ShowUnit(p.caster, true);
        SetUnitX(p.caster, p.curX);
        SetUnitY(p.caster, p.curY);
        DestroyEffect(p.other);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
